﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kugar.Core.BaseStruct
{
    public class VM_PagedList<T>:IEnumerable<T>
    {
        public IEnumerable<T> Data { set; get; }

        public int PageIndex { set; get; }

        public int PageSize { set; get; }

        public int TotalCount { set; get; }

        public int PageCount
        {
            get
            {
                if (TotalCount % PageSize >0)
                {
                    return TotalCount/PageSize + 1;
                }
                else
                {
                    return TotalCount/PageSize;
                }
            }
        }

        public IEnumerator<T> GetEnumerator()
        {
            if (Data==null)
            {
                yield break;
            }

            foreach (var item in Data)
            {
                yield return item;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
